package CookieDemo;

import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;







public class CookieDemo {
	private WebDriver driver;
	private String baseUrl;

	@BeforeMethod
	public void setUp() throws Exception {
		System.setProperty("webdriver.chrome.driver",
				"D:/selenium/selenium drivers/chromedriver.exe");
		driver = new ChromeDriver();
		baseUrl = "http://control.blog.sina.com.cn/admin/article/article_add.php";
		// Puts a Implicit wait, Will wait for 10 seconds before throwing
		// exception
		driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
		// Maximize the browser
		// driver.manage().window().maximize();

	}

	@Test
	public void main() throws Exception{
		driver.get(baseUrl);
		driver.findElement(By.id("username")).clear();
		driver.findElement(By.id("username")).sendKeys("手机号");
		driver.findElement(By.id("password")).clear();
		driver.findElement(By.id("password")).sendKeys("密码");
		driver.findElement(By.xpath("//*[@id='vForm']/div[2]/div/ul/li[7]/div[1]/input")).click();
		Thread.sleep(3000);
		
		//获取cookie
		Set<Cookie> cookie = driver.manage().getCookies();
		System.out.println(cookie);
		//填入内容
		driver.findElement(By.id("articleTitle")).clear();
		driver.findElement(By.id("articleTitle")).sendKeys("标题");
		WebElement xf = driver.findElement(By.xpath("//*[@id='SinaEditor_Iframe']/iframe"));
		driver.switchTo().frame(xf);
		//String body = "Hello world again again!";
		driver.findElement(By.tagName("body")).sendKeys("sdf sdf ");
		driver.switchTo().defaultContent();
		Thread.sleep(5000);
		Actions action = new Actions(driver); 
		action.clickAndHold(driver.findElement(By.id("articlePostBtn"))).perform();
		action.release(driver.findElement(By.id("articlePostBtn"))).perform();
		
		
		
		
		
		
		
	}

	@AfterMethod
	public void tearDown() throws Exception {
		//driver.quit();
		
		
	}

}
